package com.aikon.wht.spring.controller;

import com.aikon.wht.crawler.TestOfJsoup;
import com.aikon.wht.spring.Temp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.aikon.wht.model.constants.CommonConstants;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * Created by haitao.wang on 2016/11/29.
 */
@Controller
@Slf4j
public class BaseController {

    @Autowired
    private TestOfJsoup testOfJsoup;

    @Autowired
    private Temp temp;

    @RequestMapping("login")
    String login(ModelMap modelMap) {
        modelMap.addAttribute("inner_page", "login.ftl");
        return CommonConstants.TEMPLATE;
    }

    @RequestMapping("firstpage")
    String firstpage(ModelMap modelMap) {
        modelMap.addAttribute("inner_page", "firstpage.ftl");
        return CommonConstants.TEMPLATE;
    }

    @RequestMapping("crawlIwjwHot")
    @ResponseBody
    String crawlIwjwHot() {
        try {
            testOfJsoup.main(new String[1]);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }

    @RequestMapping("tmp")
    @ResponseBody
    String getTmp(){
        return temp.getTmp();
    }
}

